package com.persondemo.videoappliction.ui.dianping.presenter;

import com.persondemo.videoappliction.bean.DianPingDetilsBean;
import com.persondemo.videoappliction.bean.ShopDetilsBean;
import com.persondemo.videoappliction.net.BaseApi;
import com.persondemo.videoappliction.net.BaseObserver;
import com.persondemo.videoappliction.net.RxSchedulers;
import com.persondemo.videoappliction.ui.base.BasePresenter;
import com.persondemo.videoappliction.ui.dianping.contract.DPdetilsContract;

import javax.inject.Inject;

public class DPdetilsPresenter extends BasePresenter<DPdetilsContract.View> implements DPdetilsContract.Presenter {
    BaseApi baseApi;

    @Inject
    public DPdetilsPresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void getshop(String id) {
        baseApi.getshop(id)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<ShopDetilsBean>() {
                    @Override
                    public void onSuccess(ShopDetilsBean shopDetilsBean) {
                        mView.loadshop(shopDetilsBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }

    @Override
    public void getdainping(String id, String page,String type) {
        baseApi.getdianping(id, page,type)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<DianPingDetilsBean>() {
                    @Override
                    public void onSuccess(DianPingDetilsBean dianPingDetilsBean) {
                        if (page.equals("1")){
                            mView.loaddianping(dianPingDetilsBean);
                        }else {
                            mView.loadmore(dianPingDetilsBean);
                        }

                    }
                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }
}
